package gdts.core.master;

import gdts.common.data.type.VArray;
import gdts.common.data.type.VInteger;
import gdts.common.data.type.VMatrix;
import gdts.common.data.type.Variable;
import gdts.common.module.ModuleBase;
import gdts.common.module.annotation.Command;
import gdts.common.util.Util;

/**
 * Wykonawczy moduł Nadzorcy.
 * 
 * @author Maciej Milczarek
 */
public class SystemModule extends ModuleBase {

    @Command(id = "WAIT")
    public void wait(VInteger inMilis) {
        try {
            Thread.sleep(inMilis.longValue());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Command(id = "ADD_TO_ARRAY")
    public void addToArray(VArray array, Variable var) {
        array.add(var.duplicate());
    }

    @Command(id = "INIT_MATRIX")
    public void initMatrix(VMatrix matrix, VInteger height, VInteger width) {
        matrix.resizeAndClean((int) height.longValue(), (int) width.longValue());
    }

    @Command(id = "INCREMENT")
    public void increment(VInteger var) {
        var.setValue(var.add(new VInteger(1L)));
    }

    @Command(id = "DECREMENT")
    public void decrement(VInteger var) {
        var.setValue(var.substract(new VInteger(1L)));
    }

    @Command(id = "PRINT")
    public void print(Variable obj) {
        System.out.print("FROM SCRIPT AT " + Util.timeString() + ": " + obj.toString());
    }

    @Command(id = "PRINTLN")
    public void println(Variable obj) {
        System.out.println("FROM SCRIPT AT " + Util.timeString() + ": " + obj.toString());
    }
}